<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	
    <title>产品列表</title>
    <base href="<%=basePath%>">
    
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
	function selectAll() {   
	    var arryObj = document.getElementsByName("selectedids")   
	    for ( var i = 0; i < arryObj.length; i++) {   
	  
	        if (typeof arryObj[i].type != "undefined"  
	                && arryObj[i].type == 'checkbox')   
	            arryObj[i].checked = true;   
	    }   
	}   
	  
	function unSelectAll() {   
	    var arryObj = document.getElementsByName("selectedids");   
	    for ( var i = 0; i < arryObj.length; i++) {   
	        if (typeof arryObj[i].type != "undefined"  
	                && arryObj[i].type == 'checkbox')   
	            ;   
	        arryObj[i].checked = false;   
	    }   
	}  
	
	</script>
	
	<script  type="text/javascript">
			function deletebatch() {
				var arryObj = document.getElementsByName("selectedids");
				var idArrays = Array();
				for( var i=0; i<arryObj.length; i++) {
					if(typeof arryObj[i].type != "undefined" 
						&& arryObj[i].type == 'checkbox' && arryObj[i].checked == true ) {
						idArrays[i] = arryObj[i].value;
					}
				}
				// alert(idArrays.length);
				if(idArrays.length==0) {
					alert("请先选择");
					return;
				}
				var strParam = "";
				for(var i=0; i<idArrays.length; i++) {
					//alert(idArrays[i].value);
					strParam += "selectedids=" + idArrays[i] + "&";
				}
				// alert(strParam);
				// var account = document.loginForm.account.value;
				// var password = document.loginForm.password.value;
				
				var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");;
				//try {
					// FireFox,Opera8.0+,Safari
					//xmlHttp = new XMLHttpRequest();
				//} catch (e) {
					// IE
					// IE6.0+
					//xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				//} catch (e){
					// IE5.5+
					//xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
				//} catch (e) {
					//alert("您的浏览器不支持AJAX!");
					//return;
				//}
				xmlHttp.open("GET", "Product_deletebatch.action?" + strParam, true);
				xmlHttp.onreadystatechange=function(){
					if(xmlHttp.readyState==4){
						//alert(xmlHttp.responseText);
						// xmlHttp.responseText纯粹是标示输出的内容 
						// result.innerHTML = xmlHttp.responseText;
						
					} else {
						//result.innerHTML = "正在 删除,请稍候....";
					}
				}
				xmlHttp.send();//xmlHttp提交
			}
	</script>
  </head>
  
  <body>
  <center>
    产品管理<br><br><br>
    <a href="test/commerce/product_add.jsp">添加产品</a><br><hr>
    
    <table border="">
    	<tr>
    		<td><input type="checkbox" name="all" value="all" onclick="if(this.checked) selectAll(); else unSelectAll()" /></td>
    		<td>ID</td>
    		<td>产品名称</td>
    		<td>所属网店</td>
    		<td>所属分类</td>
    		<td>发布日期</td>
    		<td>是否可见</td>
    		<td>操作</td>
    	</tr>
    	<s:iterator value="productList" id="product">
    		<tr>
    			<td><input type="checkbox" name="selectedids" value="${ product.id}" /></td>
    			<td><s:property value="#product.id"/></td>
    			<td><s:property value="#product.productName"/></td>
    			<td><s:property value="#product.category.shop.shopName"/></td>
    			<td><s:property value="#product.category.categoryName"/></td>
    			<td><s:date name="#product.publishDate" format="yyyy-MM-dd"/></td>
    			<td><s:property value="#product.isVisiable"/></td>
    			
    			<s:url var="delete" value="Product_delete.action">
					<s:param name="productId" value="#product.id"></s:param>
				</s:url>
				<s:url var="editform" value="Product_editform.action">
					<s:param name="productId" value="#product.id"></s:param>
				</s:url>
				<s:url var="view" value="Product_view.action">
					<s:param name="productId" value="#product.id"></s:param>
				</s:url>
				<td>
				<s:a href="%{delete}">删除</s:a> &nbsp;&nbsp;
				<s:a href="%{editform}">修改</s:a> &nbsp;&nbsp;
				<s:a href="%{view}">详细信息</s:a>
    			</td>
    		</tr>
    	</s:iterator>
    </table><br><br>
    	<a href="javascript:deletebatch();">批量删除</a>
    <br><br>
    <div id="page">
    <a href="Product_list.action?pageModel.pageNo=${pageModel.topPageNo }">首页</a> &nbsp;&nbsp;
    <a href="Product_list.action?pageModel.pageNo=${pageModel.previousPageNo }">上一页</a>	&nbsp;&nbsp;
    <s:iterator value="#pageModel.showPages" id="showPageNo">
		<a href="Product_list.action?pageModel.pageNo=${showPageNo }">${showPageNo }</a> &nbsp;&nbsp;
    </s:iterator>
    <a href="Product_list.action?pageModel.pageNo=${pageModel.nextPageNo }">下一页</a> &nbsp;&nbsp;
    <a href="Product_list.action?pageModel.pageNo=${pageModel.bottomPageNo }">尾页</a> &nbsp;&nbsp;
    (${pageModel.pageNo }/${pageModel.totalPages })
    </div>
    </center>
  </body>
</html>
